package com.zzyl.service.impl;

import com.zzyl.dto.LoginDto;
import com.zzyl.mapper.UserMapper;
import com.zzyl.service.UserService;
import com.zzyl.utils.JwtUtil;
import com.zzyl.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description UserServiceImpl
 * @Author Taoxiuli
 * @Date 2024-09-10
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVo loginInfo(LoginDto loginDto) {
        UserVo userVo = userMapper.getLoginInfo(loginDto);
        if(userVo != null){
            Map<String,Object> map = new HashMap<>();
            map.put("id",loginDto.getId());
            map.put("username",loginDto.getUsername());
            map.put("password",loginDto.getPassword());
            userVo.setUserToken(JwtUtil.createJWT("itheima",600000,map));
            return userVo;
        }
        return null;
    }
}
